package com.telecom.util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;

public class SessionUtil {
    public static final SqlSessionFactory FACTORY; // 静态代码块
    public static final String CONFIG_FILE = "config.xml";
    static {
        SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
        try {
            FACTORY = builder.build(Resources.getResourceAsStream(CONFIG_FILE));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    public static SqlSession getSession() {
        return FACTORY.openSession();
    }
    public static SqlSession getSession(boolean autoCommit) {
        return FACTORY.openSession(autoCommit);
    }

}
